/****************************************Copyright (c)****************************************************
**                                      
**                                 http://www.powermcu.com
**
**--------------File Info---------------------------------------------------------------------------------
** File name:               main.c
** Descriptions:            The FreeRTOS application function
**
**--------------------------------------------------------------------------------------------------------
** Created by:              AVRman
** Created date:            2010-11-8
** Version:                 v1.0
** Descriptions:            The original version
**
**--------------------------------------------------------------------------------------------------------
** Modified by:             
** Modified date:           
** Version:                 
** Descriptions:            
**
*********************************************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "FreeRTOS.h"
#include "task.h"
#include "config.h"
#include "var.h"
#include "queue.h"
#include "semphr.h"
#include "sim900.h"
/* Private define ------------------------------------------------------------*/


/* Private function prototypes -----------------------------------------------*/
//static void prvSetupHardware( void );
//void vLEDTask(void * pvArg);
/*******************************************************************************
* Function Name  : main
* Description    : Main program
* Input          : None
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
SemaphoreHandle_t xSem_sim_cmd;
SemaphoreHandle_t xSem_sim_smsArrive;
SemaphoreHandle_t xSem_sim_incommingCall;
xQueueHandle Sim_CmdQueue;
SemaphoreHandle_t xSem_pc_usart;
xQueueHandle Sim_NewSMSQueue;
int main(void)
{

  vSemaphoreCreateBinary(xSem_sim_smsArrive);
  vSemaphoreCreateBinary(xSem_sim_incommingCall);  
  xSem_pc_usart = xSemaphoreCreateMutex();
    vSemaphoreCreateBinary(xSem_sim_cmd);
  Sim_CmdQueue = xQueueCreate(10,sizeof(SimCmd));
  Sim_NewSMSQueue = xQueueCreate(10,20);//do dai 1 thong bao co tin nhan dang \r\n+CMTI... khong qua duoc 20 ki tu
  xTaskCreate( vInitHardware, ( const char * ) NULL , 800 , NULL , 1, NULL );  


  /* Start the scheduler. */
  vTaskStartScheduler();	

  return 0;
}

/*******************************************************************************
* Function Name  : vLEDTask
* Description    : LED Task
* Input          : None
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
void vLEDTask(void * pvArg)
{

  while(1)
  {
    /*====LED-ON=======*/
	GPIO_SetBits(GPIOC , GPIO_Pin_0);
	GPIO_SetBits(GPIOC , GPIO_Pin_7);
	GPIO_SetBits(GPIOD , GPIO_Pin_10);
	GPIO_SetBits(GPIOD , GPIO_Pin_11);
    vTaskDelay(500);	

	/*====LED-OFF=======*/ 
	GPIO_ResetBits(GPIOC , GPIO_Pin_0);
	GPIO_ResetBits(GPIOC , GPIO_Pin_7);
	GPIO_ResetBits(GPIOD , GPIO_Pin_10);
	GPIO_ResetBits(GPIOD , GPIO_Pin_11);
    vTaskDelay(500);	 
  }
}

/*******************************************************************************
* Function Name  : prvSetupHardware
* Description    : None
* Input          : None
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
//static void prvSetupHardware( void )
//{
//  /* Configure HCLK clock as SysTick clock source. */
//  SysTick_CLKSourceConfig( SysTick_CLKSource_HCLK );
//}

/*******************************************************************************
* Function Name  : GPIO_Configuration
* Description    : Configure GPIO Pin
* Input          : None
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/





#ifdef  USE_FULL_ASSERT

/**
  * @brief  Reports the name of the source file and the source line number
  *   where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{ 
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {
  }
}
#endif

/*********************************************************************************************************
      END FILE
*********************************************************************************************************/
